(function () {
  let data = {
    day365: { orders: '20,301,987', amount: '99834' },
    day90: { orders: '301,987', amount: '9834' },
    day30: { orders: '1,987', amount: '3834' },
    day1: { orders: '987', amount: '834' },
  };
  $('.filter a').on('click', function () {
    // 点击时先清除定时器，完成高亮和数据切换后，再开启定时器
    clearInterval(timer);
    $(this).addClass('active').siblings().removeClass('active');
    let index = $(this).attr('data-key');
    $('.order h4').eq(0).html(data[index].orders);
    $('.order h4').eq(1).html(data[index].amount);
    nowIndex = $(this).index(); //使得封装里面的nowIndex有值可取，从点击的nowIndex开始加一定时循环
    // 获取nowIndex下标，重新开启定时器
    load();
  });
  let timer;
  let nowIndex = 0;
  function load() {
    timer = setInterval(function () {
      nowIndex++;
      if (nowIndex === $('.filter a').length) {
        nowIndex = 0;
      }
      //   $('.filter a')
      //     .eq(nowIndex)
      //     .addClass('active')
      //     .siblings()
      //     .removeClass('active');
      //   let index = $('.filter a').eq(nowIndex).attr('data-key');
      //   $('.order h4').eq(0).html(data[index].orders);
      //   $('.order h4').eq(1).html(data[index].amount);
      $('.filter a').eq(nowIndex).click();
    }, 1000);
  }
  load();
})();
